const WebsiteConfigurationPromise = (async function () {
  // let version = "0.1";
  // let logoURL = "/logo.png";
  // let websiteName = "文章内容平台";
  // let websiteDescription = "文章内容平台";
  // let copyright = "尘跃";
  // let ICPString = undefined;
  // let 公网安备案 = undefined;
  // let 公网安备案号 = undefined;
  // let 萌ICP备案号 = undefined;
  // await fetch("/api/configuration/website/version")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       version = text;
  //     }
  //   });
  // await fetch("/api/configuration/website/logo")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       logoURL = text;
  //     }
  //   });
  // await fetch("/api/configuration/website/name")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       websiteName = text;
  //     }
  //   });
  // await fetch("/api/configuration/website/description")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       websiteDescription = text;
  //     }
  //   });
  // await fetch("/api/configuration/website/copyright")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       copyright = text;
  //     }
  //   });
  // await fetch("/api/configuration/website/icp")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       ICPString = text;
  //     }
  //   });
  // await fetch("/api/configuration/website/公网安备案")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       公网安备案 = text;
  //       公网安备案号 = 公网安备案.match(/(\d+)/)[0];
  //     }
  //   });
  // await fetch("/api/configuration/website/萌ICP备案号")
  //   .then((response) => response.text())
  //   .then((text) => {
  //     if (text) {
  //       萌ICP备案号 = text;
  //     }
  //   });

  let configuration = {};
  await fetch("/api/configuration/website")
    .then((response) => response.json())
    .then((result) => {
      configuration = result.data;
    });
  if (configuration.公网安备案)
    configuration.公网安备案号 = configuration.公网安备案.match(/(\d+)/)[0];
  const websiteName = configuration.name;
  const websiteDescription = configuration.description;
  const websiteURL = configuration.url;
  const copyright = configuration.copyright;

  // 修改页面信息
  function noUndefined(v) {
    return v ? v : {};
  }

  if (
    window.location.pathname === "/" ||
    window.location.pathname === "/index" ||
    window.location.pathname === "/index.html"
  ) {
    document.title = websiteName;
  } else {
    document.title = websiteName + "——" + document.title;
  }
  noUndefined(document.querySelector("meta[name='description']")).content =
    websiteDescription;

  noUndefined(document.querySelector("meta[property='og:site_name']")).content =
    websiteName;
  noUndefined(document.querySelector("meta[property='og:title']")).content =
    document.title;
  noUndefined(document.querySelector("meta[property='og:url']")).content =
    window.location.href;
  noUndefined(document.querySelector("meta[name='og:image']")).content =
    websiteURL + "/favicon.png";
  noUndefined(
    document.querySelector("meta[property='og:description']"),
  ).content = websiteDescription;

  noUndefined(document.querySelector("meta[name='twitter:title']")).content =
    document.title;
  noUndefined(
    document.querySelector("meta[name='twitter:description']"),
  ).content = websiteDescription;
  noUndefined(document.querySelector("meta[name='twitter:image']")).content =
    websiteURL + "/favicon.png";
  noUndefined(document.querySelector("meta[name='twitter:creator']")).content =
    `@${copyright}`;

  // return {
  //   version,
  //   logo: logoURL,
  //   logoURL,
  //   websiteName,
  //   copyright,
  //   ICPString,
  //   公网安备案,
  //   公网安备案号,
  //   萌ICP备案号,
  // };
  return configuration;
})();
const APPConfigruationPromise = WebsiteConfigurationPromise;
